<template>
  <div style="min-height: 100%;width: 100%" class="wsjz-b2">
    <el-row>
      <el-col :xs="{span: 20, offset: 2}" :sm="{span: 20, offset: 2}" :md="{span: 12, offset: 6}" :lg="{span: 8, offset: 8}">
        <el-card class="wsjz-stu-card">
          <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="100px" class="demo-ruleForm">
            <h1 style="text-align:center">乾-元</h1>
            <el-form-item label="账号" prop="username">
              <el-input v-model="loginForm.username"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
              <el-input v-model="loginForm.password" show-password></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
              <el-button @click="resetForm('loginForm')">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  export default {
    name: 'Login',
    data() {
      return {
        loginForm: {
          username: 'admin',
          password: '123456'
        },
        loginRules: {
          username: [{ required: true, trigger: 'blur', message: '账号不能为空' }],
          password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
        },
      }
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$store.dispatch('user/login', this.loginForm).then(() => {
              this.$router.push({ path: '/' })
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          } else {
            return false
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style lang="scss">
 .wsjz-b2 {
  background-image: url(./../../assets/b2.png);
  background-repeat: no-repeat;
  background-size: cover;
  background-color: rgba(0,0,0,1); 
}
.wsjz-stu-card {
  height:500px;
  transform: translateY(30%);
}
</style>
